package com.nbjtjc.safe.service.edu;

import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.edu.EduCertificateRetrainMapper;
import com.nbjtjc.safe.model.edu.EduCertificateRetrain;

@Service
public class EduCertificateRetrainService{
	@Autowired
	  private EduCertificateRetrainMapper eduCertificateRetrainMapper;
		
	  public Result add(EduCertificateRetrain eduCertificateRetrain){
		        Result result=new Result();
		        if(ObjectUtil.isNull(eduCertificateRetrain)
		        		||ObjectUtil.isNull(eduCertificateRetrain.getEduCertificateId())
		        		){		            
		        	result.setFalse("新增记录和持证培训ID不能为空");
		            return result;
		        }
//主键为空或库中无此主键则为新建，插入数据
		        if(ObjectUtil.isNull(eduCertificateRetrain.getId())|| ObjectUtil.isNull(eduCertificateRetrainMapper.selectByPrimaryKey(eduCertificateRetrain.getId()))){
		        	int res=eduCertificateRetrainMapper.insertSelective(eduCertificateRetrain);
			        if(res==0){
			            result.setFalse("插入复训记录失败");
			            return result;
			        }

		        }else
		        {
		        	int res=eduCertificateRetrainMapper.updateByPrimaryKeySelective(eduCertificateRetrain);
		        	 if(res==0){
		        		 result.setFalse("更新复训记录失败");
				         return result;

		        	 }

		        }
				result.setData(eduCertificateRetrain);

		        return result;
		    }


	  
	  public Result delete(int eduCertificateRetrainId){
	      Result result=new Result();
	      if(ObjectUtil.isNull(eduCertificateRetrainId)){
	          result.setFalse("删除对象不能为空");
	          return result;
	      }
	      int res = eduCertificateRetrainMapper.deleteByPrimaryKey(eduCertificateRetrainId);
	      if(res==0){
	    	  result.setFalse("删除失败");
		      return result;
	
	      }
	      return result;
	  }

	  
	  public Result find(EduCertificateRetrain eduCertificateRetrain) {
	      Result result = new Result();
	      PageHelper.startPage(eduCertificateRetrain.getPageCurrent(), eduCertificateRetrain.getPageSize());
	      List<EduCertificateRetrain> eduCertificateRetrains = eduCertificateRetrainMapper.select(eduCertificateRetrain);
	      result.setData(new PageInfo<>(eduCertificateRetrains));

	      return result;
	  }
}
